<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Db;
class Garden extends Controller
{
	public function index(){
		$types=Db::name('gardentype')->select();
		$this->assign("types",$types);
		$gardens=Db::query("select * from garden g,gardentype t where g.tid=t.tid order by id desc");
		$this->assign("gardens",$gardens);
		return $this->fetch();
	}
	public function delete($id){
		//查询图片名
		//方法1
		// $pic=Db::name("garden")->where("id",$id)->find();//一维数组
		// dump($pic);
		$pic1=Db::name("garden")->field('pic')->find($id);//一维数组
		$picname=$pic1["pic"];
		// $pic2=Db::name("garden")->where("id",$id)->select();//二维数组
		// dump($pic2);
		if(file_exists(ROOT_PATH.'public'.DS.'static'.DS.'uploads'.DS.$picname)){
			unlink(ROOT_PATH.'public'.DS.'static'.DS.'uploads'.DS.$picname);
		}
		if(Db::name("garden")->delete($id)){
			$this->success("删除成功");
		}else{
			$this->error("删除失败");
		}

	}
}